<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="雇主ID" prop="masterId">-->
<!--        <el-input-->
<!--          v-model="queryParams.masterId"-->
<!--          placeholder="请输入雇主ID"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="公司ID" prop="companyId">-->
<!--        <el-input-->
<!--          v-model="queryParams.companyId"-->
<!--          placeholder="请输入公司ID"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="雇主类型" prop="masterType">
        <el-select v-model="queryParams.masterType" placeholder="请选择雇主类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.recruit_master_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="岗位名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入岗位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="薪资待遇" prop="salary">
        <el-input
          v-model="queryParams.salary"
          placeholder="请输入薪资待遇"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经验要求" prop="experience">
        <el-input
          v-model="queryParams.experience"
          placeholder="请输入经验要求"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历要求" prop="education">
        <el-input
          v-model="queryParams.education"
          placeholder="请输入学历要求"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="职位要求" prop="requirement">-->
<!--        <el-input-->
<!--          v-model="queryParams.requirement"-->
<!--          placeholder="请输入职位要求"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="职位描述" prop="des">-->
<!--        <el-input-->
<!--          v-model="queryParams.des"-->
<!--          placeholder="请输入职位描述"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.recruit_job_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="联系方式" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联系方式"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信昵称" prop="wxUserName">
        <el-input
          v-model="queryParams.wxUserName"
          placeholder="请输入微信昵称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:jobs:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:jobs:edit']"
        >修改</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['business:jobs:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['business:jobs:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jobsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="微信昵称" align="center" prop="wxUserName" />
      <el-table-column label="雇主类型" align="center" prop="masterType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.recruit_master_type" :value="scope.row.masterType"/>
        </template>
      </el-table-column>
      <el-table-column label="岗位名称" align="center" prop="name" />
      <el-table-column label="联系方式" align="center" prop="phone" />
      <el-table-column label="薪资待遇" align="center" prop="salary" />
      <el-table-column label="经验要求" align="center" prop="experience" />
      <el-table-column label="学历要求" align="center" prop="education" />
      <el-table-column label="公司名称" align="center" prop="companyName" />
<!--      <el-table-column label="职位要求" align="center" prop="requirement" />-->
<!--      <el-table-column label="职位描述" align="center" prop="des" />-->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <div :style="{color: statusColorMap[scope.row.status]}">
            <dict-tag :options="dict.type.recruit_job_status" :value="scope.row.status"/>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:jobs:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:jobs:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改招聘岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="雇主ID" prop="masterId">
          <el-input v-model="form.masterId" placeholder="请输入雇主ID" />
        </el-form-item>
        <el-form-item label="公司ID" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入公司ID" />
        </el-form-item>
        <el-form-item label="雇主类型" prop="masterType">
          <el-select v-model="form.masterType" placeholder="请选择雇主类型">
            <el-option
              v-for="dict in dict.type.recruit_master_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="岗位名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="薪资待遇" prop="salary">
          <el-input v-model="form.salary" placeholder="请输入薪资待遇" />
        </el-form-item>
        <el-form-item label="经验要求" prop="experience">
          <el-input v-model="form.experience" placeholder="请输入经验要求" />
        </el-form-item>
        <el-form-item label="学历要求" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历要求" />
        </el-form-item>
        <el-form-item label="职位要求" prop="requirement">
          <el-input v-model="form.requirement" placeholder="请输入职位要求" />
        </el-form-item>
        <el-form-item label="职位描述" prop="des">
          <el-input v-model="form.des" placeholder="请输入职位描述" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in dict.type.recruit_job_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="微信用户名" prop="wxUserName">
          <el-input v-model="form.wxUserName" placeholder="请输入微信用户名" />
        </el-form-item>
        <el-form-item label="公司名称" prop="companyName">
          <el-input v-model="form.companyName" placeholder="请输入公司名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJobs, getJobs, delJobs, addJobs, updateJobs, exportJobs } from "@/api/business/jobs";

export default {
  name: "Jobs",
  dicts: ['recruit_master_type', 'recruit_job_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 招聘岗位表格数据
      jobsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        masterId: null,
        companyId: null,
        masterType: null,
        name: null,
        salary: null,
        experience: null,
        education: null,
        requirement: null,
        des: null,
        status: null,
        phone: null,
        wxUserName: null,
        companyName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      statusColorMap: {
        '0': '#f1a63f',
        '1': 'green',
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询招聘岗位列表 */
    getList() {
      this.loading = true;
      listJobs(this.queryParams).then(response => {
        this.jobsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        jobId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        masterId: null,
        companyId: null,
        masterType: null,
        name: null,
        salary: null,
        experience: null,
        education: null,
        requirement: null,
        des: null,
        status: null,
        phone: null,
        wxUserName: null,
        companyName: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.jobId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加招聘岗位";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const jobId = row.jobId || this.ids
      getJobs(jobId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改招聘岗位";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.jobId != null) {
            updateJobs(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJobs(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const jobIds = row.jobId || this.ids;
      this.$modal.confirm('是否确认删除招聘岗位编号为"' + jobIds + '"的数据项？').then(function() {
        return delJobs(jobIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有招聘岗位数据项？').then(() => {
        this.exportLoading = true;
        return exportJobs(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
